# -*- coding: UTF-8 -*-
# 描述数据卖家（移动终端）
import random

COST = 5  # 获取数据成本
P1 = 20  # 初始报价
DELTA = 1  # 价格递减速度


class Seller:
    def __init__(self, id, qbuyer, price=[], quality=[]):
        self.id = id  # index
        self.cost = COST  # 成本
        self.w = []  # 向其发送报价的买家
        self.flag = True  # 本轮是否有改变？
        # 给各个买家的报价
        if (len(price) == 0):
            self.price = [P1] * qbuyer
        else:
            self.price = price
        # 服务质量，后续用AoI代替
        if (len(quality) == 0):
            self.quality = []
            for _ in range(qbuyer):
                self.quality.append(random.randint(1, 10))
        else:
            self.quality = quality

    # 寻找所有报价高于成本的买家
    def findBuyerSet(self, t):
        self.w = []
        for i in range(len(t)):
            if (self.price[i] > self.cost):
                self.w.append(i)

    # 调整（降低）价格
    def adjustPrice(self, bindex):
        self.price[bindex] = max(self.price[bindex] - DELTA, self.cost)
